{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class NumArray(object):\n",
    "\n",
    "    def __init__(self, nums):\n",
    "        \"\"\"\n",
    "        :type nums: List[int]\n",
    "        \"\"\"\n",
    "        self.sum = [0] * len(nums)\n",
    "        if len(nums) > 0:\n",
    "            self.sum[0] = nums[0]\n",
    "            for i in range(1, len(nums)):\n",
    "                self.sum[i] = self.sum[i-1] + nums[i]\n",
    "\n",
    "    def sumRange(self, i, j):\n",
    "        \"\"\"\n",
    "        :type i: int\n",
    "        :type j: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        if len(self.sum) == 0:\n",
    "            return None\n",
    "        if i == 0:\n",
    "            return self.sum[j]\n",
    "        else:\n",
    "            return self.sum[j] - self.sum[i-1]\n",
    "        \n",
    "\n",
    "\n",
    "# Your NumArray object will be instantiated and called as such:\n",
    "# obj = NumArray(nums)\n",
    "# param_1 = obj.sumRange(i,j)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
